#include<stdio.h>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
int mice[1000];
int order[1000];
int res[1000];
int np;
int ng;
bool msort(const int& a,const int& b){
    return mice[a]>mice[b];
}
int main(){
    scanf("%d %d",&np,&ng);
    int i=0;
    while(i<np){
        scanf("%d",&mice[i++]);
    }
    i=0;
    while(i<np){
        scanf("%d",&order[i++]);
    }

    if(ng==1){
        sort(order,order+np,msort);
        for(int k=0;k<np;k++){
            res[order[k]]=k+1;
        }
        printf("%d",res[0]);
        for(int k=1;k<np;k++){
            printf(" %d",res[k]);
        }
        return 0;
    }

    vector<int> group;
    vector<int> outplayers;
    queue<int> winners;
    queue<int> players;

    for(i=0;i<np;i++){
        players.push(order[i]);
    }

    int j;
    int round=0;
    while(players.size()>1){
        queue<int> emp;
        winners.swap(emp);
        outplayers.clear();
        round++;
        //printf("Round:%d\n",round);
        while(!players.empty()){
            int frontId = players.front();
            players.pop();
            group.push_back(frontId);
            if(group.size()==ng||players.empty()){
                sort(group.begin(),group.end(),msort);
                //for(int k=0;k<group.size();k++){
                //    printf("%d ",group[k]);
                //}
                //printf("\n");
                winners.push(group[0]);
                for(int k=1;k<group.size();k++)
                    outplayers.push_back(group[k]);
                group.clear();
            }
        }
        int this_round_rank = winners.size()+1;
        for(int k=0;k<outplayers.size();k++){
            //printf("%d ",outplayers[k]);
            res[outplayers[k]]=this_round_rank;
        }
        //printf("\n");
        players=winners;
        //printf("end of round\n");
    }

    res[winners.front()]=1;

    printf("%d",res[0]);
    for(int k=1;k<np;k++){
        printf(" %d",res[k]);
    }
    return 0;
}
